import type { DictItem } from '@/types'
import http from '@/utils/request'

const teamLeaders: DictItem[] = [{
  label: '是',
  value: 'T'
}, {
  label: '否',
  value: 'F'
}]

const teamTypes: DictItem[] = [{
  label: '坐席',
  value: 'Seats'
}, {
  label: '业务',
  value: 'Biz'
}]

const operationTypes: DictItem[] = [{
  label: '礼品',
  value: 'Gift'
}, {
  label: '套餐',
  value: 'Combo'
}, {
  label: '业务类型',
  value: 'BizType'
}]

function listToMap(list: DictItem[]): Record<string | number, string | number> {
  return list.reduce((sum, cur) => {
    return {
      ...sum,
      [cur.value]: cur.label
    }
  }, {})
}

function isNotEmpty(val: any): boolean {
  return !!val || (val === 0)
}

function getStatusDict(url: string) {
  return http.get(url).then(res => {
    return (res.data || []).map((item: { name: any; code: any }) => {
      return {
        label: item.name,
        value: item.code
      }
    })
  })
}

export {
  teamLeaders,
  teamTypes,
  operationTypes,
  getStatusDict,
  listToMap,
  isNotEmpty
}
